﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Xml.Linq;

namespace WebApplication6
{
    public partial class index : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

            string spname = Request["spname"];
            string fenlei = Request["fenlei"];
            string order = Request["order"];
            string url = "";
            string sql = "select * from t_product  where ";
            if (fenlei != null) {

                sql = sql + " fenlei='" + fenlei + "' ";
                sql = sql + " and  ";

                url = url + " &fenlei=" +fenlei;

            }

            if (spname != null)
            {

                sql = sql + " spname  like '%" + spname + "%' ";
                sql = sql + " and  ";

                url = url + " &spname=" +spname;

            }

            sql = sql + " 1=1 ";
            if (order == "1")
            {
                sql = sql + " order by id desc";
            }
            else if (order == "2")
            {
                sql = sql + " order by tuijian desc,id desc";
            }
            else {
                sql = sql + " order by id desc";
            }


            DataTable dt = SQLHelper.ExecuteDataTable(sql);


            //   数据源
            PagedDataSource Pgds = new PagedDataSource();
            //        

           

            Pgds.DataSource = dt.DefaultView;

            //        设置允许分页
            Pgds.AllowPaging = true;
            //        每页显示为6行
            Pgds.PageSize = 10;
            //        显示总共页数
            //
            lblTotalPage.Text = Pgds.PageCount.ToString();
            //        当前页
            int CurrentPage;
            //        请求页码为不为null设置当前页，否则为第一页
            if (Request.QueryString["Page"] != null)
            {

                CurrentPage = Convert.ToInt32(Request.QueryString["Page"]);
            }

            else
            {

                CurrentPage = 1;
            }
            //   当前页所引为页码-1
            Pgds.CurrentPageIndex = CurrentPage - 1;
            //   显示当前页码
            lblCurrentPage.Text = CurrentPage.ToString();
            //   如果不是第一页，通过参数Page设置上一页为当前页-1，否则不显示连接
            if (!Pgds.IsFirstPage)
            {
                //            Request.CurrentExecutionFilePath为当前请求虚拟路径
                lnkPrev.NavigateUrl = Request.CurrentExecutionFilePath + "?Page=" + Convert.ToString(CurrentPage - 1)+url;
            }
            //        End If
            //   如果不是最后一页，通过参数Page设置下一页为当前页+1，否则不显示连接
            if (!Pgds.IsLastPage)
            {
                //    Request.CurrentExecutionFilePath为当前请求虚拟路径
                lnkNext.NavigateUrl = Request.CurrentExecutionFilePath + "?Page=" + Convert.ToString(CurrentPage + 1) + url;
            }
            //   模板绑定数据源  
            Repeater1.DataSource = Pgds;
            Repeater1.DataBind();


        }

        protected void Repeater1_ItemCommand(object source, RepeaterCommandEventArgs e)
        {

        }
    }
}
